跳到主要内容

String 对象

String 对象用于表示和操作字符序列。

版本新增方法
ES5 及更早charAt(), charCodeAt(), concat(), indexOf(), lastIndexOf(), slice(), substring(), substr(), replace(), split(), toLowerCase(), toUpperCase(), trim(), match(), search(), localeCompare()
ES6 (2015)模板字符串(...${}...), includes(), startsWith(), endsWith(), repeat()
ES11 (2016)❌ 无新增
ES9 (2018)padStart(), padEnd()
ES10 (2019)trimStart(), trimEnd()
ES11 (2021)replaceAll()

常见的 String 静态属性方法 🤖️

常见的 String 实例方法 🤖️

includes() 是否包含,返回 true。

  • 区分大小写
  const strings = "abc12345 bac12345 cba12345";
const result = strings.includes("bac12345");
console.log("输出结果:", `${strings}\n`, result);

参考链接

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String